package io.gitee.kotle.base.library

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import io.gitee.kotle.android.mvvm.mvvminterface.MvvmViewType
import io.gitee.kotle.android.utils.invisible
import io.gitee.kotle.android.utils.visible
import io.gitee.kotle.base.databinding.ModuleBaseViewBaseUiErrorBinding
import io.gitee.kotle.base.databinding.ModuleBaseViewBaseUiLoadingBinding

/**
 *
 * 描述：
 *
 * 创建人：jiale.wei
 * 创建时间：2021/11/23 11:03 上午
 *
 */
interface IUiViewHelper {

    val baseUiView: BaseUiView?

    val toolbar: Toolbar?

    fun isNeedBaseUiView() = false

    fun isNeedToolBar() = false

    fun createBaseUiView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
        needToolbar: Boolean,
        needBaseUi: Boolean,
    ): ViewGroup?

    fun handleBaseUiView(
        inflater: LayoutInflater,
        beforeView: ViewGroup?,
        createView: MvvmViewType?,
        savedInstanceState: Bundle?
    ): MvvmViewType?

    fun showContent() {
        baseUiView?.let {
            it.loadingBinding.root.invisible()
            it.errorBinding.root.invisible()
        }
    }

    fun showError(block: ((ModuleBaseViewBaseUiErrorBinding) -> Unit)? = null) {
        baseUiView?.let {
            it.loadingBinding.root.invisible()
            it.errorBinding.root.visible()
            block?.invoke(it.errorBinding)
        }
    }

    fun showLoading(block: ((ModuleBaseViewBaseUiLoadingBinding) -> Unit)? = null) {
        baseUiView?.let {
            it.loadingBinding.root.visible()
            it.errorBinding.root.invisible()
            block?.invoke(it.loadingBinding)
        }
    }
}